/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.actionform;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import database.InventoryDAO;
import java.util.ArrayList;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Product;
import org.apache.catalina.Session;


import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/ExportExcel")
public class ProductExportAction extends ActionSupport{
    private final static String SUCCESS = "success";
    private ArrayList<Product> products;
    private ProductForm productForm;

    public ProductForm getProductForm() {
        return productForm;
    }

    public void setProductForm(ProductForm productForm) {
        this.productForm = productForm;
    }
    public InventoryDAO inventoryDAO = new InventoryDAO();

    public ArrayList<Product> getProducts() {
        return products;
    }

    public void setProducts(ArrayList<Product> products) {
        this.products = products;
    }
    
    
    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @org.apache.struts2.convention.annotation.Action( value = "ProductForm", results = {
        @Result(name = "success", location = "/w_inventory2.jsp"),     
    })
    public String Inventory()
    {
        Map session = ActionContext.getContext().getSession();
        
         //session = request.getSession();
    //session.setAttribute("userName", loginBean.getUsername());
        products = inventoryDAO.getProductForInventory(1);
        session.put("products", products);
            //productForm.setProducts(products);
//        ProductForm userForm = new ProductForm();;
//        
//        //System.out.println(inventoryDAO.getProductForInventory());
//        userForm.setProducts(inventoryDAO.getProductForInventory());
        return SUCCESS;
    }
//    public ActionForward Inventory(ActionMapping mapping, ActionForm form,
//            HttpServletRequest request, HttpServletResponse response)
//            throws Exception {
//        ProductForm userForm = (ProductForm) form;
//        InventoryDAO inventoryDAO = new InventoryDAO();
//        userForm.setProducts(inventoryDAO.getProductForInventory());    
//        return mapping.findForward(SUCCESS);
//    }
}
